home *** CD-ROM | disk | FTP | other *** search
/ Trading on the Edge / Trading On The Edge - CD-ROM Toolkit (Wayzata Technology)(2031)(1994).bin / pc / mac_file / vendor_d / neuralwa / nw2v50 / twod_map.c < prev    next >
Text File  |  1993-08-23  |  8KB  |  404 lines

  1. /* twod_map.c */
  2.  
  3. /* 2 input node, 1 output node  userio program */
  4. /* Assumptions:
  5.    (a)  x,y Values in file are assumed to lie between
  6.    -1.5 and 1.5.
  7.    (b)  output value between 0 and 1
  8.  
  9.    If used with save-best, set objective function to be UserIO.
  10. */
  11.  
  12.  
  13. /************************************************************************
  14.  * Copyright(C) 1987-1992 NeuralWare Inc                                *
  15.  * Penn Center West, IV-227, Pittsburgh, PA 15276                       *
  16.  * Telephone: (412) 787-8222    FAX: (412) 787-8220                     *
  17.  *                                                                      *
  18.  * All rights reserved.  No part of this program may be reproduced,     *
  19.  * stored in a retrieval system, or transmitted, in any form or by any  *
  20.  * means, electronic, mechanical, photocopying, recording or otherwise  *
  21.  * without the prior written permission of the copyright owner,         *
  22.  * NeuralWare, Inc.                                                     *
  23.  *                                                                      *
  24.  *                          PROPRIETARY NOTICE                          *
  25.  *                                                                      *
  26.  * This document is the property of NeuralWare, Inc. and contains       *
  27.  * trade-secrets and other proprietary information.  The information    *
  28.  * herein is reserved as proprietary to NeuralWare, and is not to be    *
  29.  * published, reproduced, copied, disclosed, used, or reverse           *
  30.  * engineered without the express written consent of a duly authorized  *
  31.  * representative of NeuralWare.                                        *
  32.  ************************************************************************
  33.  */
  34.  
  35. #define UIO_SERVER             1
  36. #define SERVER_EMULATOR_FILE   1
  37. #define SKIP_COMPAT_DATA       1
  38. #include "userutl.h"
  39. #include "uio_strc.h"
  40. #include "uio_tran.h"
  41. #include "uio_reqs.pro"
  42. #include "uio_cmds.pro"
  43.  
  44. #include <math.h>
  45.  
  46. #ifdef MAC
  47. #include "macuio.redef"
  48. #endif
  49.  
  50. #define DO_BLIT 1
  51.  
  52. #define W_WDTH  200  /* basic defining parameters */
  53. #define W_HGHT  200  /* height of graph */
  54. long file_count = 0l;
  55.  
  56. #define SBUF_ALC 200
  57. TEXT  sbuf[SBUF_ALC];
  58. int   back_color;
  59. int   on_color;
  60. #define COLOR_MAX 12
  61. int   color[COLOR_MAX];
  62. int   savebestf;    /* Save best flag */
  63.  
  64. float      xin, yin;       /* Real coords of recall point */
  65. int        x_rcl, y_rcl;   /* Graphics coords of recall point */
  66.  
  67.  
  68. #define W0 1
  69. #define W1 2
  70.  
  71. #define PIXEL_WIDTH 3
  72.  
  73. #ifdef DO_BLIT
  74. #define BLIT_DIMX  (((W_WDTH-1)/PIXEL_WIDTH)+1)
  75. #define BLIT_DIMY  (((W_HGHT-1)/PIXEL_WIDTH)+1)
  76. TEXT    blit[BLIT_DIMY][BLIT_DIMX];
  77. #endif
  78.  
  79. NINT UIO_Init(file)
  80. TEXT *file;
  81. {
  82.   NINT       ret_val = UIO_OK;
  83.   NINT       xsize, ysize, ncolor, chrx, chry; /* graphics parameters */
  84.   NINT       ypos;
  85.   TEXT      *filen;
  86.   FILE      *fp;
  87.  
  88.   savebestf = 0;
  89.  
  90.   /* Get screen parameters */
  91.   ug_gparms( &xsize, &ysize, &ncolor, &chrx, &chry);
  92.   
  93.   if ( ncolor < 8 ) {
  94.     color[0]   = 0;
  95.     color[1]   = 0;
  96.     color[2]   = 0;
  97.     color[3]   = 0;
  98.     color[4]   = 0;
  99.     color[5]   = 0;
  100.     color[6]   = 1;
  101.     color[7]   = 1;
  102.     color[8]   = 1;
  103.     color[9]   = 1;
  104.     color[10]  = 1;
  105.     color[11]  = 1;
  106.     on_color   = 1;
  107.   } else {
  108.     color[0]   = 4;
  109.     color[1]   = 4;
  110.     color[2]   = 4;
  111.     color[3]   = 11;
  112.     color[4]   = 11;
  113.     color[5]   = 7;
  114.     color[6]   = 7;
  115.     color[7]   = 9;
  116.     color[8]   = 9;
  117.     color[9]   = 1;
  118.     color[10]  = 1;
  119.     color[11]  = 1;
  120.  
  121.     on_color   = 6;
  122.   }
  123.  
  124.   back_color = color[0];
  125.   
  126.   ypos = ysize - W_HGHT - 100;
  127.   if (ypos < 75)
  128.      ypos = 95;
  129.   if (ypos > 300)
  130.      ypos = 300;
  131.  
  132.   /* Set up windows */
  133.   ug_window(W0, back_color, 20, ypos+25, 20+W_WDTH, ypos+25+W_HGHT);
  134.   ug_window(W1, 0, 20, ypos, 20+W_WDTH, ypos+24);
  135.  
  136.   /* Get file count so we can calculate epochs */
  137.   ug_rdfileinf(&filen,0,&file_count);
  138.  
  139.   if (file_count <= 0l)
  140.      file_count = 1l;
  141.  
  142.   return(ret_val);
  143. }
  144.  
  145.  
  146. NINT UIO_Term(process)
  147. NINT process;
  148. {
  149.   NINT ret_val = UIO_OK;
  150.  
  151.   return(ret_val);
  152. }
  153.  
  154. NINT UIO_Attention()
  155. {
  156.   NINT ret_val = UIO_OK;
  157.  
  158.   return(ret_val);
  159. }
  160.  
  161.  
  162. NINT UIO_Learn_Start()
  163. {
  164.    NINT ret_val = UIO_OK;
  165.  
  166.    /* Set up learn file; use selected file */
  167.    ug_fileio("", 0, 1, 1, 1);
  168.  
  169.    return(ret_val);
  170. }
  171.  
  172. NINT UIO_Learn_Input(LayN, nPEs, Datap)
  173. NINT  LayN;
  174. NINT  nPEs;
  175. SREAL *Datap;
  176. {
  177.   NINT ret_val = UIO_OK;
  178.  
  179.   return(ret_val);
  180. }
  181.  
  182. NINT UIO_Learn_Output(LayN, nPEs, Datap)
  183. NINT  LayN;
  184. NINT  nPEs;
  185. SREAL *Datap;
  186. {
  187.   NINT ret_val = UIO_OK;
  188.  
  189.   return(ret_val);
  190. }
  191.  
  192.  
  193. NINT UIO_Learn_Result(LayN, nPEs, Datap)
  194. NINT  LayN;
  195. NINT  nPEs;
  196. SREAL *Datap;
  197. {
  198.    NINT  ret_val = UIO_OK;
  199.   
  200.    return(ret_val);
  201. }
  202.  
  203. NINT UIO_Learn_End()
  204. {
  205.   NINT ret_val = UIO_OK;
  206.  
  207.   return(ret_val);
  208. }
  209.  
  210. NINT UIO_Recall_Start()
  211. {
  212.   NINT ret_val = UIO_OK;
  213.   TEXT   *sp;
  214.   CTRIO_T ctrs[8];         /* Counters */    
  215.   NINT    epch;
  216.   
  217.   x_rcl = PIXEL_WIDTH>>1;
  218.   y_rcl = PIXEL_WIDTH>>1;
  219.  
  220. #ifdef DO_BLIT
  221.   PutStr("Testing ...");
  222. #else
  223.   ug_winclr(W0);
  224.   ug_winclr(W1);
  225.  
  226.   /* Read counters to get learn count */
  227.   ug_ctrio(ctrs,0);
  228.   
  229.   epch = ctrs[2]/((float)file_count);
  230.  
  231.   sprintf(sbuf,"Epoch:  %ld", (long)epch);
  232.   ug_puts(W1,on_color,0,15,4,sbuf,0);
  233.  
  234. #endif
  235.  
  236.   return(ret_val);
  237. }
  238.  
  239.  
  240. NINT UIO_Read(LayN, nPEs, Datap)
  241. NINT  LayN;
  242. NINT  nPEs;
  243. SREAL *Datap;
  244. {
  245.   NINT ret_val = UIO_OK;
  246.  
  247.   /* Assume data lies between -1.5 and 1,5 */
  248.   xin = ((3*x_rcl) / (float)W_WDTH) - 1.5;
  249.   yin = ((3*y_rcl) / (float)W_HGHT) - 1.5;
  250.  
  251.   Datap[0] = xin;
  252.   Datap[1] = yin;
  253.  
  254.   return(ret_val);
  255.  
  256. }
  257.  
  258. NINT UIO_Write(LayN, nPEs, Datap)
  259. NINT  LayN;
  260. NINT  nPEs;
  261. SREAL *Datap;
  262. {
  263.   NINT  ret_val = UIO_OK;
  264.   SREAL outval;
  265.   NINT  wx;
  266. #ifdef DO_BLIT
  267.   NINT  blitx, blity;
  268. #endif
  269.  
  270.   outval = Datap[0];
  271.  
  272.   wx = (COLOR_MAX*outval);
  273.   if (wx >= COLOR_MAX)
  274.      wx = COLOR_MAX-1;
  275.   else if (wx < 0)
  276.      wx = 0;
  277.   
  278. #ifdef DO_BLIT
  279.   blitx = (x_rcl-1)/PIXEL_WIDTH;
  280.   blity = (y_rcl-1)/PIXEL_WIDTH;
  281.  
  282.   blit[blity][blitx] = color[wx];
  283. #else
  284.   if (color[wx] != back_color)
  285.      ug_boxf(W0, color[wx], 0,
  286.              x_rcl-1,y_rcl-1,x_rcl+1,y_rcl+1);
  287. #endif
  288.   
  289.   x_rcl += PIXEL_WIDTH;
  290.   if (x_rcl > W_WDTH) {
  291.      x_rcl = PIXEL_WIDTH>>1;
  292.      y_rcl += PIXEL_WIDTH;
  293. #ifdef DO_BLIT
  294.      /* Want to know we're still alive */
  295.      PutStr(".");
  296. #endif
  297.   }
  298.  
  299. #ifdef DO_BLIT
  300.   /* End of recall; now BLIT the image */
  301.   if (y_rcl >= W_HGHT) {
  302.      CTRIO_T ctrs[8];         /* Counters */    
  303.      NINT    epch;
  304.  
  305.      ug_winclr(W0);
  306.      ug_winclr(W1);
  307.  
  308.      ug_blit(W0, 0, 0, 0, PIXEL_WIDTH, PIXEL_WIDTH,
  309.              BLIT_DIMX, BLIT_DIMY, (char *)&blit[0][0] );
  310.  
  311.      /* Read counters to get learn count */
  312.      ug_ctrio(ctrs,0);
  313.   
  314.      epch = ctrs[2]/((float)file_count);
  315.  
  316.      sprintf(sbuf,"Epoch:  %ld", (long)epch);
  317.      ug_puts(W1,on_color,0,15,4,sbuf,0);
  318.  
  319.      PutStr("\n");
  320.   }
  321. #endif
  322.  
  323.   if (y_rcl >= W_HGHT)
  324.      return( UIO_EXIT);
  325.   else
  326.      return( UIO_OK);
  327.  
  328. }
  329.  
  330. NINT UIO_Write_Step(LayN, nPEs, Datap)
  331. NINT  LayN;
  332. NINT  nPEs;
  333. SREAL *Datap;
  334. {
  335.   NINT ret_val = UIO_OK;
  336.  
  337.   return(ret_val);
  338. }
  339.  
  340.  
  341. NINT UIO_Recall_Test(LayN, nPEs, Datap)
  342. NINT  LayN;
  343. NINT  nPEs;
  344. SREAL *Datap;
  345. {
  346.   NINT ret_val = UIO_OK;
  347.  
  348.   return(ret_val);
  349. }
  350.  
  351. NINT UIO_Recall_End()
  352. {
  353.   NINT ret_val = UIO_OK;
  354.  
  355.   if (!savebestf) {
  356.      PutStr("Hit <Enter> to continue:");
  357.      GetStr( );
  358.   }
  359.  
  360.   return(ret_val);
  361. }
  362.  
  363. NINT UIO_Instrument(Instrument_id, nDataElems, DataElemp)
  364. NINT  Instrument_id;
  365. NINT  nDataElems;
  366. SREAL *DataElemp;
  367. {
  368.   NINT ret_val = UIO_OK;
  369.  
  370.   return(ret_val);
  371. }
  372.  
  373. /* FUNCTION */
  374. NINT UIO_ObjFunc(eoeflag, DataElemp)
  375. NINT  eoeflag;
  376. SREAL *DataElemp;
  377. {
  378.   NINT ret_val = UIO_OK;
  379.  
  380.   if (eoeflag)
  381.      savebestf = 0;   /* Clear save best flag */
  382.   else
  383.      savebestf = 1;   /* Tell recall we are in savebest mode */
  384.  
  385.   return(ret_val);
  386. }
  387.  
  388. NINT UIO_Rewind()
  389. {
  390.   NINT ret_val = UIO_OK;
  391.  
  392.   return(ret_val);
  393. }
  394.  
  395. NINT UIO_Explain(LayN, nPEs, Datap)
  396. NINT  LayN;
  397. NINT  nPEs;
  398. SREAL *Datap;
  399. {
  400.   NINT ret_val = UIO_OK;
  401.  
  402.   return(ret_val);
  403. }
  404.